package com.ds.bar;

import com.ds.common.JDSException;
import com.ds.dsm.admin.temp.JavaTempNavTree;
import com.ds.enums.IconEnumstype;

import com.ds.esd.custom.nav.annotation.TabsAnnotation;
import com.ds.esd.custom.tree.annotation.TreeAnnotation;
import com.ds.esd.dsm.domain.enums.*;
import com.ds.esd.dsm.enums.DSMType;
import com.ds.esd.tool.ui.component.list.TreeListItem;

@TabsAnnotation(singleOpen = true)
@TreeAnnotation(heplBar = true, caption = "出码方案")
public class DomainTempItem extends TreeListItem {


    public DomainTempItem() throws JDSException {
        this.caption = "模板分类";
        this.id = "AllTempGallery";
        this.className = "dsm.admin.temp.AllTempGrid";
        this.iniFold = false;
        this.imageClass = "spafont spa-icon-settingprj";
        DSMType[] dsmTypes = DSMType.getDomainTypes();
        for (DSMType dsmType : dsmTypes) {
            DomainTempItem domainInstTree = new DomainTempItem(dsmType);
            this.addChild(domainInstTree);
        }
        this.addTagVar("dsmType", DSMType.all.getType());
    }

    public DomainTempItem(DSMType dsmType) throws JDSException {
        this.caption = dsmType.getName();
        this.imageClass = dsmType.getImageClass();
        this.className = "dsm.admin.temp.CodeTempGrid";
        this.iniFold = false;
        this.id = dsmType.getType();
        this.addTagVar("dsmType", dsmType.getType());

        if (dsmType.equals(DSMType.customDomain)) {
            this.className = "dsm.admin.temp.domain.AllTempGrid";
            CustomDomainType[] repositoryTypes = CustomDomainType.values();
            for (CustomDomainType type : repositoryTypes) {
                this.addChild(new DomainTempItem(type));
            }
        } else if (dsmType.equals(DSMType.userDomain)) {
            this.className = "dsm.admin.temp.domain.AllTempGrid";
            CustomDomainType[] repositoryTypes = CustomDomainType.values();
            for (CustomDomainType type : repositoryTypes) {
                this.addChild(new DomainTempItem(type));
            }
        } else if (dsmType.equals(DSMType.supportDomain)) {
            this.className = "dsm.admin.temp.domain.AllTempGrid";
            CustomDomainType[] repositoryTypes = CustomDomainType.values();
            for (CustomDomainType type : repositoryTypes) {
                this.addChild(new DomainTempItem(type));
            }
        }
    }

    public DomainTempItem(CustomDomainType customDomainType) throws JDSException {
        this.caption = customDomainType.getName();
        this.imageClass = customDomainType.getImageClass();
        this.id = DSMType.customDomain.getType() + "_" + customDomainType.getType();
        this.addTagVar("dsmType", DSMType.customDomain.getType());
        this.addTagVar("customDomainType", customDomainType.getType());

        switch (customDomainType) {
            case bpm:
                BpmDomainType[] types = BpmDomainType.values();
                this.className = "dsm.admin.temp.bpm.AllTempGrid";
                for (BpmDomainType type : types) {
                    this.addChild(new JavaTempNavTree( type,customDomainType));
                }
                break;
            case msg:
                MsgDomainType[] msgtypes = MsgDomainType.values();
                this.className = "dsm.admin.temp.msg.AllTempGrid";
                for (MsgDomainType type : msgtypes) {
                    this.addChild(new DomainTempItem(customDomainType, type));
                }
                break;
            case org:
                OrgDomainType[] orgtypes = OrgDomainType.values();
                this.className = "dsm.admin.temp.org.AllTempGrid";
                for (OrgDomainType type : orgtypes) {
                    this.addChild(new JavaTempNavTree(type,customDomainType));
                }
                break;
            case nav:
                NavDomainType[] navtypes = NavDomainType.values();
                this.className = "dsm.admin.temp.nav.AllTempGrid";
                for (NavDomainType type : navtypes) {
                    this.addChild(new DomainTempItem(customDomainType, type));
                }
                break;
            case vfs:
                VfsDomainType[] vfstypes = VfsDomainType.values();
                this.className = "dsm.admin.temp.vfs.AllTempGrid";
                for (VfsDomainType type : vfstypes) {
                    this.addChild(new DomainTempItem(customDomainType, type));
                }
                break;
        }

    }

    public DomainTempItem(CustomDomainType customDomainType, IconEnumstype domainType) throws JDSException {
        this.caption = domainType.getName();
        this.imageClass = domainType.getImageClass();
        this.id = DSMType.customDomain.getType() + "_" + customDomainType.getType() + "_" + domainType.getType();
        this.className = "dsm.admin.temp." + customDomainType.getType() + ".AllTempGrid";
        this.addTagVar("dsmType", DSMType.customDomain.getType());
        this.addTagVar("customDomainType", customDomainType.getType());
        this.addTagVar("domainType", domainType.getType());
    }


}
